package com.lingyi.algorithm.lab2;

import cn.hutool.core.collection.CollUtil;

import java.util.ArrayList;

/**
 * @author chenweilong
 * @email 1433471850@qq.com
 * @date 2020-08-19 18:01
 */
public class DeleteLink {


    public static void main(String[] args) {



        ArrayList<Integer> ints = CollUtil.newArrayList(1, 2, 3, 4,4, 5,4, 6);

        Node head = new Node();
        head.setT(-1);

        for (Integer anInt : ints) {
            Node headNext = head.getNext();

            Node newNode = new Node();
            newNode.setT(anInt);
            newNode.setNext(headNext);


            head.setNext(newNode);
        }



        int del = 4;



        Node p = head;


        Node e;

        while ((e = p.getNext()) != null) {
            if (e.getT().equals(del)) {
                Node eNext = e.getNext();
                p.setNext(eNext);
                continue;
            }
            p = e;
        }

        while (head.getNext() != null) {
            head = head.getNext();
            System.out.println(head.getT());
        }




    }
}
